package com.hym.app;

import java.util.ArrayList;

import android.R.integer;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;

import com.hym.hymlistview.DataEntity;
import com.hym.hymlistview.XAdapter;
import com.hym.hymlistview_x.HymListview;
import com.hym.hymlistview_x.HymListview.IHYMListViewListener;
import com.hym.myrrefreshlistview.R;
/**
 * 基于XlistView写的ListView的使用
 * */
public class XActivity extends Activity implements IHYMListViewListener{
	private Context mContext;
	private HymListview mListview;
	private Handler mHandler;
	
	private ArrayList<DataEntity> dataList=new ArrayList<DataEntity>();
	private XAdapter adapter;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_x);
		mContext=this;
		mListview=(HymListview)findViewById(R.id.hymListView);
		mListview.setPullRefreshEnable(true);
		generateData();
		adapter=new XAdapter(mContext, dataList);
		mListview.setAdapter(adapter);
		mListview.setHymListViewListener(this);
		mHandler=new Handler();
	}
	
	/**
	 * 生成相关数据
	 */
	private void generateData() {
		for (int i = 0; i< 20; ++i) {
			DataEntity entity = new DataEntity();
			entity.setName("默认数据");
			entity.setDes("这是一个XListview的应用");
			entity.setInfo("50w用户");
			dataList.add(entity);
		}
	}

	@Override
	public void onRefresh() {
		mHandler.postDelayed(new Runnable() {
			
			@Override
			public void run() {
				dataList.clear();
				//获取新数据
				for(int i=0;i<10;i++){
					DataEntity dataEntity=new DataEntity();
					dataEntity.setDes("数据");
					dataEntity.setInfo("不错啊");
					dataEntity.setName("测试应用");
					dataList.add(dataEntity);
					//adapter.notifyDataSetChanged();\
					adapter=new XAdapter(mContext, dataList);
					mListview.setAdapter(adapter);
					onLoad();
				}
			}
		}, 200);
		
	}
	private void onLoad() {
//		mListview.stopRefresh();
//		mListview.stopLoadMore();
//		mListview.setRefreshTime("刚刚");
	}

	@Override
	public void onLoadMore() {
		// TODO Auto-generated method stub
		
	}

}
